package academic.ui.client.jquery;

public class Facebook {
	
	public static native void init() /*-{
		$wnd.FB.init({appId: '173045196040681', status: true, cookie: true,
	        xfbml: true});
       }-*/;
	
	public static native void wallPost(String message, String name, String description,
			String link, String picture, String caption) /*-{
		var params = {};
		params['message'] = message;
		params['name'] = name;
		params['description'] = description;
		params['link'] = link;//'http://apps.facebook.com/summer-mourning/'
		params['picture'] = picture; //'http://summer-mourning.zoocha.com/uploads/thumb.png'
		params['caption'] = caption;
		  
		$wnd.FB.api('/me/feed', 'post', params, function(response) {
		  if (!response || response.error) {
		    $wnd.alert('Error occured');
		  } else {
		    $wnd.alert('Published to stream - you might want to delete it now!');
		  }
		});
	}-*/;
	
	public static native void createEvent(String name, String description,
			String start_time, String end_time, String location, String venue) /*-{
		 $wnd.FB.getLoginStatus(function(response) {
		 	if (response.session) {
				var params = {};
				params['name'] = name;
				params['description'] = description;
				params['start_time'] = start_time;//A JSON string containing an ISO-8601 formatted date/time
				params['end_time'] = end_time;//A JSON string containing an ISO-8601 formatted date/time
				params['location'] = location;
				params['venue'] = venue; //A JSON object containing street, city, state, zip, country, latitude, and longitude fields
				
				$wnd.FB.api('/me/events', 'post', params, function(response) {
				  if (!response || response.error) {
				    $wnd.alert('Error occured');
				  } else {
				  	
				  	//replace this with some response method to show the user that they have added the event
				    $wnd.alert('Published to stream - you might want to delete it now!');
				  }
				});
		 	}
		 });
	}-*/;
}
